package util

import (
	"yunj/pkg/yunj/core/builder"

	"github.com/gin-gonic/gin"
)

// 获取datas中的构建器
func GetDatasBuilder[BT builder.BuilderInterface](datas map[string]interface{}) (builder BT) {
	builderRaw, exists := datas["builder"]
	if !exists {
		return
	}
	if b, ok := builderRaw.(BT); ok {
		builder = b
	}
	return
}

// 获取datas中的构建器gin上下文
func GetDatasBuilderGinContext(datas map[string]interface{}) (ctx *gin.Context) {
	builderRaw, exists := datas["builder"]
	if !exists {
		return
	}
	if b, ok := builderRaw.(builder.BuilderInterface); ok {
		ctx = b.GetGinContext()
	}
	return
}
